package org.mixed.config;

import org.mixed.core.interceptor.AuthorizationInterceptor;
import org.mixed.core.interceptor.DefaultAuthorizationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MixWebConfiguration implements WebMvcConfigurer {
    @Autowired
    private MixProperties properties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(properties.getWeb() + "/**")
                .addResourceLocations("classpath:/mix-editor/");
    }

    @Bean
    public AuthorizationInterceptor authorizationInterceptor(MixProperties properties){
        MixProperties.Security security = properties.getSecurity();
        return new DefaultAuthorizationInterceptor(security.getUsername(), security.getPassword());
    }
}
